﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using mdryden.Core.Localization;
using LastoRevival.Service.Contracts.Models.Validation;

namespace LastoRevival.Service.Contracts.Models
{
	public class EditProfileModel : IValidatableObject
	{

		public int UserID { get; set; }

		public string Username { get; set; }

		[Required(ErrorMessageResourceType = typeof(ValidationMessageLoader), ErrorMessageResourceName = "User_EmailRequiredError")]
		[DataType(DataType.EmailAddress)]
		[StringLength(30, ErrorMessageResourceType = typeof(ValidationMessageLoader), ErrorMessageResourceName = "StringLengthError")]
		public string Email { get; set; }
		
		[StringLength(1000)]
		public string Signature { get; set; }

		public bool HideEmail { get; set; }


		public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
		{
			var errors = new List<ValidationResult>();

			// ensure email address has an @ sign
			// the rest of the validation will come from whether the registration email gets sent properly or not.
			if (!EmailValidator.IsValid(Email))
			{
				var error = new ValidationResult(LanguageLoader.GetWord("User_EmailInvalidError"), new[] { "Email" });
				errors.Add(error);
			}

			return errors;
		}
	}
}
